<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="项目名称" prop="outdoorProjectName">
                <el-input
                    v-model="queryParams.outdoorProjectName"
                    placeholder="请输入项目名称"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="路侧订单id" prop="pkParkRecordId">
              <el-input
                  v-model="queryParams.pkParkRecordId"
                  placeholder="请输入路侧订单id"
                  clearable
                  @keyup.enter="handleQuery"
              />
            </el-form-item>
            <el-form-item label="车牌号" prop="plateNumber">
              <el-input
                  v-model="queryParams.plateNumber"
                  placeholder="请输入车牌号"
                  clearable
                  @keyup.enter="handleQuery"
              />
            </el-form-item>
            <el-form-item label="退款状态" prop="refundStatusList">
               <el-select v-model="queryParams.refundStatusList" placeholder="退款状态" clearable style="width: 200px">
                  <el-option
                     v-for="dict in dict.type.refund_status"
                     :key="dict.value"
                     :label="dict.label"
                     :value="dict.value"
                  />
               </el-select>
            </el-form-item>
						<el-form-item label="创建时间" prop="dateRange">
						  <el-date-picker
						    v-model="queryParams.dateRange"
						    type="datetimerange"
						    range-separator="-"
						    start-placeholder="开始日期"
						    value-format="yyyy-MM-dd HH:mm:ss"
						    style="width:333px;"
						    :default-time="['00:00:00','23:59:59']"
						    end-placeholder="结束日期">
						  </el-date-picker>
						</el-form-item>

            <el-form-item >
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="路侧订单id" align="center" prop="pkParkRecordId"/>
            <el-table-column label="所属项目名称" align="center" prop="outdoorProjectName"/>
            <el-table-column label="车牌号" align="center" prop="plateNumber" :show-overflow-tooltip="true"/>
            <el-table-column label="退款状态" align="center" prop="refundStatus">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.refund_status" :value="row.refundStatus" />
                </template>
            </el-table-column>
            <el-table-column label="退款申请人" align="center" prop="applyUserName"/>
            <el-table-column label="退款金额" align="center" prop="refundAmount"/>
            <el-table-column label="退款备注" align="center" prop="remark"/>
            <el-table-column label="退款申请时间" align="center" prop="applyTime"/>
            <el-table-column label="退款时间" align="center" prop="refundTime"/>
            <el-table-column label="审核时间" align="center" prop="verifyTime"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="300">
               <template slot-scope="{row}">
                  <el-button link type="primary" icon="Delete"
                  @click="handleDetail(row)" v-if="row.refundStatus === 1" v-hasPermi="['system:eaOutdoorRefund:edit']" >审核</el-button>
               </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      <!-- 审核弹框 -->
      <el-dialog :title="title" :visible.sync="openExamine" width="60%" append-to-body>
        <div class="diy-mx-8">
          <!---审核表单-->
          <div class="diy-mt-4">
            <el-form ref="form" :model="form" :rules="rules" label-width="88px">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="审核状态" prop="refundStatus">
                    <el-radio-group v-model="form.refundStatus">
                      <el-radio
                        v-for="option in examineList"
                        :key="option.value"
                        :label="option.value"
                      >{{option.label}}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item label="审核意见" prop="remark">
                    <el-input v-model="form.remark" :rows="6" type="textarea" placeholder="请输入"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" :loading="subLodding" @click="submitForm">确 认</el-button>
          <el-button @click="openExamine = false">关 闭</el-button>
        </div>
      </el-dialog>
    </div>
</template>

<script >
import * as api from "@/api/roadside/refundRecord";

export default {
  name: 'refundRecord',
  dicts: ['refund_status',],
  components: {  },
  data() {
    return {
      examineList: [
        {value:3,label:'通过'},
        {value:2,label:'不通过'},
      ],
      form: {},// 表单参数
      // 表单校验
      rules: {
        refundStatus: [
          { required: true, message: "审核状态不能为空", trigger: "change" }
        ],
        // remark: [
        //   { required: true, message: "审核意见不能为空", trigger: "blur" }
        // ],
      },
      // 弹出层标题
      title: "",
      //审核弹出层
      openExamine: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
        dateRange:[],
      },
      // 总条数
      total: 0,
      list:[],//页面数据
      subLodding:false,//提交加载
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    submitForm(){//审核确定
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.subLodding = true
          api.toVerify(this.form).then((response) => {
            if (response.code != 200) return;
            if(!response.data) {
              this.$modal.msgWarning("退款失败");
            }else{
              this.$modal.msgSuccess("操作成功");
            }
            this.openRefundApply = false;
            this.subLodding = false
          }).catch(error=>this.subLodding=false);
        }
      });
    },
    handleDetail(e){//审核点击
      this.form = {
        id:e.id,
        refundStatus: 3,
      }
      this.title = '审核'
      this.openExamine = true
    },
    getList() {
      this.loading = true;
      if(!this.queryParams.dateRange) this.queryParams.dateRange = []
      let queryParams = {...this.queryParams}
      if(this.queryParams.dateRange.length) {
        queryParams.startTime = this.queryParams.dateRange[0]
        queryParams.endTime = this.queryParams.dateRange[1]
      }
      api.eaOutdoorRecoveryRefundList(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
  }
}
</script>
